package com.kevin.handler;

import com.kevin.core.RequestHolder;
import com.kevin.core.RpcFuture;
import com.kevin.core.RpcProtocol;
import com.kevin.core.RpcResponse;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.concurrent.EventExecutorGroup;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RpcClientHandler extends SimpleChannelInboundHandler<RpcProtocol<RpcResponse>> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, RpcProtocol<RpcResponse> rpcResponseRpcProtocol) throws Exception {

        log.info("receive Rpc Server Result");
        long requestId = rpcResponseRpcProtocol.getHeader().getSessionId();
        RpcFuture<RpcResponse> rpcFuture = RequestHolder.FUTURE_MAP.remove(requestId);
        rpcFuture.getPromise().setSuccess(rpcResponseRpcProtocol.getContent()) ;

    }
}
